package com.test0102;

public class ECommercePlatform {
    public static void main(String[] args) {
                // 创建电商平台  Platform 类
        Platform platform = new Platform("京东");

        // 创建订单：订单号、客户名、订单金额  Order类
        Order o1 = new Order("001", "Alice", 200.0);
        Order o2 = new Order("002", "Bob", 150.0);
        Order o3 = new Order("003", "Charlie", 300.0);

        // 平台添加订单   Platform 方法add();
        platform.add(o1);
        platform.add(o2);
        platform.add(o3);

        // 打印所有订单信息    Platform 方法printAll();
        platform.printAll();

        // 找出订单金额最大的订单     platform 方法findMaxOrder
        Order maxOrder = platform.findMaxOrder();
        System.out.println(maxOrder);

        // 找出订单金额最小的订单    platform 方法findMinOrder
        Order minOrder = platform.findMinOrder();
        System.out.println(maxOrder);

        // 找出特定客户名的订单   platform 中findOrderByName
        Order specificOrder = platform.findOrderByName("Bob");
        System.out.println(specificOrder);

        // 计算平均订单金额    platform 中calculateAverage()
        double average = platform.calculateAverage();
        System.out.println(average);

    }
}
class Platform {
    private String plat_name;
    private Order[] orderArr = new Order[3];
    private int index = 0;

    public Platform() {
    }

    public Platform(String plat_name) {
        this.plat_name = plat_name;
    }

    public String getPlat_name() {
        return plat_name;
    }

    public void setPlat_name(String plat_name) {
        this.plat_name = plat_name;
    }

    @Override
    public String toString() {
        return "Platform{" +
                "plat_name='" + plat_name + '\'' +
                '}';
    }
    public void add(Order o){
        orderArr[index++]=o;
    }
    public void printAll(){
        for(Order a:orderArr){
            System.out.println(a);
        }
    }
    public Order findMaxOrder(){
        Order max = orderArr[0];
        for(int i=1;i<orderArr.length;i++){
            if(max.getMoney()<orderArr[i].getMoney()){
                max=orderArr[i];
            }
        }
        return max;
    }
    public Order findMinOrder(){
        Order min = orderArr[0];
        for(int i=1;i<orderArr.length;i++){
            if(min.getMoney()>orderArr[i].getMoney()){
                min=orderArr[i];
            }
        }
        return min;
    }
    public Order findOrderByName(String name){
        for(int i=0;i<orderArr.length;i++){
            if(name.equals(orderArr[i].getOrder_name())){
                return orderArr[i];
            }
        }
        return null;
    }
    public double calculateAverage(){
        double sum =0;
        for(int j =0;j<orderArr.length;j++){
            sum += orderArr[j].getMoney();
        }
        double avg = sum/orderArr.length;
        return avg;
    }
}
class Order{
    private String Order_id;
    private String Order_name;
    private double money;

    public Order() {
    }

    public Order(String order_id, String order_name, double money) {
        Order_id = order_id;
        Order_name = order_name;
        this.money = money;
    }

    public String getOrder_id() {
        return Order_id;
    }

    public void setOrder_id(String order_id) {
        Order_id = order_id;
    }

    public String getOrder_name() {
        return Order_name;
    }

    public void setOrder_name(String order_name) {
        Order_name = order_name;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    @Override
    public String toString() {
        return
                "订单号：" + Order_id +
                ", 客户名：" + Order_name + '\'' +
                ", 价格" + money ;

    }
}
